﻿<UserControl x:Class="Conmigo.Widgets.ContactHeader"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:widgets="clr-namespace:Conmigo.Widgets">
    
  <UserControl.Resources>
    <widgets:FrameUserTileConverter x:Key="frameConverter"/>
    <widgets:MailtoConverter x:Key="mailtoConverter" />
    <widgets:HideableTextConverter x:Key="hideableFormatText"/>
    <widgets:RssTitleFromUriConverter x:Key="rssConverter"/>
  </UserControl.Resources>
  
  <Grid>
    <!-- Within the header give all TextBlocks the same glow effect -->
    <Grid.Resources>
      <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
        <!-- BitmapEffects don't seem to allow the binding to pick up changes that result in empty text
             so remove the effect in that case.
         -->
        <Style.Triggers>
          <Trigger Property="Text" Value="">
            <Setter Property="BitmapEffect" Value="{x:Null}"/>
            <Setter Property="Visibility" Value="Collapsed"/>
          </Trigger>
        </Style.Triggers>
        <Setter Property="BitmapEffect">
          <Setter.Value>
            <OuterGlowBitmapEffect GlowColor="White" GlowSize="7"/>
          </Setter.Value>
        </Setter>
        <Setter Property="Margin" Value="5"/>
      </Style>
    </Grid.Resources>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto"/>
      <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Viewport3D Grid.RowSpan="2" Height="96" Width="76" x:Name="_UserTile3DViewport">
      <Viewport3D.Camera>
        <PerspectiveCamera Position="0, 0, 2.5"/>
      </Viewport3D.Camera>

      <!-- project the user tile in 3D -->
      <Viewport2DVisual3D>
        <Viewport2DVisual3D.Transform>
          <RotateTransform3D>
            <RotateTransform3D.Rotation>
              <AxisAngleRotation3D Angle="20" Axis="0, 1, 0" />
            </RotateTransform3D.Rotation>
          </RotateTransform3D>
        </Viewport2DVisual3D.Transform>

        <!-- The Geometry, Material, and Visual for the Viewport2DVisual3D -->
        <Viewport2DVisual3D.Geometry>
          <MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
                          TextureCoordinates="0,0 0,1 1,1 1,0"
                          TriangleIndices="0 1 2 0 2 3"/>
        </Viewport2DVisual3D.Geometry>

        <Viewport2DVisual3D.Material>
          <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
        </Viewport2DVisual3D.Material>

        <Image Source="{Binding Path=UserTile, Converter={StaticResource frameConverter}}" />
      </Viewport2DVisual3D>

      <!-- Lights -->
      <ModelVisual3D>
        <ModelVisual3D.Content>
          <DirectionalLight Color="White" Direction="-1,0,-3"/>
        </ModelVisual3D.Content>
      </ModelVisual3D>
    </Viewport3D>
    <TextBlock Grid.Column="1" FontSize="20" Margin="5" Text="{Binding Path=Name.FormattedName}"/>
    <ScrollViewer Grid.Column="1" Grid.Row="1" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
      <WrapPanel Orientation="Vertical">
        <!-- TODO: This Hyperlink indirection is ugly.  It should be generalized and hidden behind a control
                   rather than repeating it four times inline here...
         -->
        <TextBlock Style="{x:Null}" Visibility="{Binding ElementName=_emailInnerText, Path=Visibility}">
          <!-- Turn off text decoration because the way the text is contented
               the underline looks like strike-through -->
          <Hyperlink RequestNavigate="_OnClickLink"
                     NavigateUri="{Binding Path=Email.Address, Converter={StaticResource mailtoConverter}}"
                     TextDecorations="None">
            <TextBlock x:Name="_emailInnerText" TextDecorations="Underline" Text="{Binding Path=Email.Address}"/>
          </Hyperlink>
        </TextBlock>
        <TextBlock Text="{Binding Path=HomePhone.Number, Converter={StaticResource hideableFormatText}, ConverterParameter=Home}"/>
        <TextBlock Text="{Binding Path=WorkPhone.Number, Converter={StaticResource hideableFormatText}, ConverterParameter=Work}"/>
        <TextBlock Style="{x:Null}" Visibility="{Binding ElementName=_homesiteInnerText, Path=Visibility}">
          <!-- Turn off text decoration because the way the text is contented
               the underline looks like strike-through -->
          <Hyperlink RequestNavigate="_OnClickLink"
                     NavigateUri="{Binding Path=PersonalWebsite}"
                     TextDecorations="None">
            <TextBlock x:Name="_homesiteInnerText" TextDecorations="Underline" Text="{Binding Path=PersonalWebsite, Converter={StaticResource hideableFormatText}, ConverterParameter=Home}"/>
          </Hyperlink>
        </TextBlock>
        <TextBlock Style="{x:Null}" Visibility="{Binding ElementName=_worksiteInnerText, Path=Visibility}">
          <!-- Turn off text decoration because the way the text is contented
               the underline looks like strike-through -->
          <Hyperlink RequestNavigate="_OnClickLink"
                     NavigateUri="{Binding Path=WorkWebsite}"
                     TextDecorations="None">
            <TextBlock x:Name="_worksiteInnerText" TextDecorations="Underline" Text="{Binding Path=WorkWebsite, Converter={StaticResource hideableFormatText}, ConverterParameter=Work}"/>
          </Hyperlink>
        </TextBlock>
        <TextBlock Style="{x:Null}" Visibility="{Binding ElementName=_rssInnerText, Path=Visibility}">
          <!-- Turn off text decoration because the way the text is contented
               the underline looks like strike-through -->
          <Hyperlink RequestNavigate="_OnClickLink"
                     NavigateUri="{Binding Path=WebFeed}"
                     TextDecorations="None">
            <TextBlock x:Name="_rssInnerText" TextDecorations="Underline">
              <TextBlock.Text>
                <PriorityBinding>
                  <Binding Path="WebFeed" Converter="{StaticResource rssConverter}" ConverterParameter="RSS" IsAsync="True"/>
                  <Binding Path="WebFeed" Converter="{StaticResource hideableFormatText}" ConverterParameter="RSS" IsAsync="False"/>
                </PriorityBinding>
              </TextBlock.Text>
            </TextBlock>
          </Hyperlink>
        </TextBlock>
      </WrapPanel>
    </ScrollViewer>
  </Grid>
</UserControl>
